//Depends: settings.js
//Depends: whirlpool.js

var _settings = null;
var _whirlpool = null;

$(function() {
  // Setup
  _settings = new Settings();
  _settings.init();
  
  if (_settings.wpKey == undefined || _settings.wpKey == '') {
	_settings.wpKey = "45450-605104-763";
	_settings.save();
  }

  // Whirlpool
  _whirlpool = new Whirlpool();
  _whirlpool.init({wpKey: _settings.wpKey});
  
  //var watched = _whirlpool.getWatched();
  
	$( document ).delegate("#home", "pageshow", function() {
		UpdatePageHome();
	});
	
	$( document ).delegate("#settings", "pageshow", function() {
		UpdatePageSettings();
	});
	
	$( document ).delegate("#watched", "pageshow", function() {
		UpdatePageWatched();
	});
});

function UpdatePageHome()
{}

function UpdatePageSettings()
{}

function UpdatePageWatched()
{
	$.when( _whirlpool.getWatched() )
	.then(function(args){
		$('div#watched div.ui-content ul').html(
			$("#watchedTemplate").render( args.WATCHED )
		).listview('refresh');
	})
	.fail(function(){
		alert('UpdatePageWatched fail');
	});
}
